package HashCode和equals;

import java.util.Objects;

public class Person {
    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Person() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

   //重写equals 和 hashCode
    @Override
    public boolean equals(Object o) {
        Person otherP = (Person)o;
        if(! this.name.equals(otherP.name)) return false;
        if(this.age != otherP.age) return false;
        return true;
    }

    @Override
    public int hashCode() {
        int thisHashCode = 0;
        thisHashCode += this.name.hashCode() * 17;
        thisHashCode += this.age;
       return thisHashCode;
    }
}
